package com.t235.gc.device.controller;

import com.github.pagehelper.PageHelper;
import com.t235.gc.AjaxResult;
import com.t235.gc.device.entity.DeviceFaultRecord;
import com.t235.gc.device.service.DeviceFaultRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备故障记录表(DeviceFaultRecord)表控制层
 *
 * @author makejava
 * @since 2021-03-24 08:58:31
 */
@RestController
@RequestMapping("deviceFaultRecord")
@Api
public class DeviceFaultRecordController {
    /**
     * 服务对象
     */
    @Resource
    private DeviceFaultRecordService deviceFaultRecordService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public DeviceFaultRecord selectOne(Long id) {
        return this.deviceFaultRecordService.queryById(id);
    }

    /**
     *根据条件查询数据
     * @param deviceFaultRecord
     * @return
     */
    @GetMapping("selectAll")
    @ApiOperation("根据多条件查询设备故障列表")
    public List<DeviceFaultRecord> select(DeviceFaultRecord deviceFaultRecord,Integer pageNum,Integer pageSize){
        if(pageNum == null){
            pageNum =1 ;
        }
        if(pageSize == null){
            pageSize = 5;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<DeviceFaultRecord> deviceFaultRecordList = deviceFaultRecordService.queryAll(deviceFaultRecord);
        return deviceFaultRecordList;
    }

    @RequestMapping("/exportExcel")
    public AjaxResult exportExcel(DeviceFaultRecord deviceFaultRecord, HttpServletResponse response){
        deviceFaultRecordService.exportExcel(deviceFaultRecord,response);
        return AjaxResult.success();
    }
}
